using net_work.Rules.Appr;
using NRules;
using NRules.Fluent;

namespace net_work.Rules.Utils;

public interface IRuleEngineUtils
{
    void ExecuteRules(object[] facts);
}

public class RuleEngineUtils : IRuleEngineUtils
{
    private readonly ISessionFactory _sessionFactory;

    public RuleEngineUtils()
    {
        var repository = new RuleRepository();
        repository.Load(x => x.From(typeof(ApprovalRuleOnlyOne).Assembly));
        _sessionFactory = repository.Compile();
    }

    public void ExecuteRules(object[] facts)
    {
        var session = _sessionFactory.CreateSession();
        foreach (var fact in facts)
        {
            session.Insert(fact);
        }

        session.Fire();
    }
}